﻿using System;
//using log4net;
using Common.Logging;
using Topshelf;
using System.Timers;
using System.Text;
using Quartz;
using Quartz.Impl;

namespace SampleWindowsService
{
    public class TownCrier
    {
        private static readonly ILog _log = LogManager.GetLogger(typeof(TownCrier));
        IScheduler sched = null;
        //private static readonly ILog Logger = LogManager.GetLogger(typeof(HisSpController));
        readonly Timer _timer;
        public TownCrier()
        {
            _timer = new Timer(1000) { AutoReset = true };
            _timer.Elapsed += (sender, eventArgs) => Console.WriteLine("It is {0} and all is well", DateTime.Now);
        }
        public void Start()
        {
            ISchedulerFactory sf = new StdSchedulerFactory();
            sched = sf.GetScheduler();
            _log.InfoFormat("in.api 开始,Tick:" + DateTime.Now.ToLongTimeString());
            _timer.Start();
        }
        public void Stop()
        {
            _log.InfoFormat("in.api 关闭,Tick:" + DateTime.Now.ToLongTimeString());
            _timer.Stop();
        }
    }
    //public class Program
    //{
    //    public static void Main()
    //    {
    //        HostFactory.Run(x =>
    //        {
    //            x.Service<TownCrier>(s =>
    //            {
    //                s.ConstructUsing(name => new TownCrier());
    //                s.WhenStarted(tc => tc.Start());
    //                s.WhenStopped(tc => tc.Stop());
    //            });
    //            x.RunAsLocalSystem();

    //            x.SetDescription("访问医院接口程序");
    //            x.SetDisplayName("访问医院接口程序");
    //            x.SetServiceName("in.api");
    //        });
    //    }
    //}
}